package data;

import java.util.Collections;
import java.util.Set;


/**
 * TimeSlot
 * 
 * @author Thach Nguyen
 *
 */
public class TimeSlot {

	private final Set<ClassDays> myClassDays;
	
	private final int myStartTime;
	
	private final int myEndTime;
	
	public TimeSlot(final Set<ClassDays> theClassDays, final int theStartTime,
					final int theEndTime) {
		myClassDays = theClassDays;
		myStartTime = theStartTime;
		myEndTime = theEndTime;
	}
	
	public Set<ClassDays> getDays() {
		return Collections.unmodifiableSet(myClassDays);
	} 
	
	public int getStartTime() {
		return myStartTime;
	}
	
	public int getEndTime() {
		return myEndTime;
	}
	public boolean overlapsWith(TimeSlot theOther) {
		boolean result = false;
		if(this == theOther) {
			result = true;
		}
		else if(theOther != null && 
				this.myStartTime == theOther.myStartTime && 
				this.myEndTime == theOther.myEndTime && 
				this.myClassDays.equals(theOther.myClassDays)) {
			result = true;
		}
		return result;
	}
	
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();

		// '0-0' is To be announced
		if(myStartTime == 0){
			sb.append("TBA");
		}
		else{
			sb.append(myStartTime);
			sb.append(",");
			sb.append(myEndTime);
		}
		
		for (ClassDays day : myClassDays) {
			sb.append(",");
			sb.append(day.toString());
		}
		sb.append(" ");
		return sb.toString();
	}
	
	@Override
	public boolean equals(final Object theOther) {
		boolean result = false;
	    if (this == theOther)
	    {
	      result = true;
	    }
	    else if (theOther != null && theOther.getClass() == getClass())
	    {
	      final TimeSlot temp = (TimeSlot) theOther;
	      result = myClassDays.containsAll(temp.myClassDays) && (myStartTime == temp.myStartTime) &&
	      		   (myEndTime == temp.myEndTime);
	    }
	    return result;
	}
}

